﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class Admin_ThueCD : System.Web.UI.Page
{
    ClassThueCD ctCD = new ClassThueCD();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            if (Session["user"] != null)
            {
                MultiView1.SetActiveView(View2);
                GridView1.DataSource = ctCD.DSThueCD();
                GridView1.DataBind();
            }
            else
                Response.Redirect("DangNhap.aspx");
        }
    }
    protected void btnThem_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        GridView1.DataSource = ctCD.DSThueCD();
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        GridView1.DataSource = ctCD.DSThueCD();
        GridView1.DataBind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int mth = int.Parse(GridView1.Rows[e.RowIndex].Cells[1].Text);

        int tt = int.Parse(GridView1.Rows[e.RowIndex].Cells[2].Text);

        TextBox txtnt= (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0];
        string nt = txtnt.Text;

        TextBox txtnpt= (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0];
        string npt = txtnpt.Text;

        TextBox txtntr = (TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0];
        string ntr = txtntr.Text;

        ctCD.SuaCD(mth,tt,nt,npt,ntr);

        GridView1.EditIndex = -1;
        GridView1.DataSource = ctCD.DSThueCD();
        GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        GridView1.DataSource = ctCD.ThemThueCD(int.Parse(TextBox9.Text),TextBox4.Text,TextBox5.Text,TextBox6.Text);
        GridView1.DataBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox9.Text = "";
    }
    protected void btnTim_Click(object sender, EventArgs e)
    {
        GridView1.DataSource = ctCD.TimThueCD(TextBox1.Text, TextBox2.Text, TextBox3.Text);
        GridView1.DataBind();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox chb = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
                if (chb.Checked == true)
                {
                    int ma = Convert.ToInt32(GridView1.Rows[i].Cells[1].Text);
                    ctCD.XoaThueCD(ma);
                }
            }
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;

        }
        GridView1.DataSource = ctCD.DSThueCD();
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = ctCD.DSThueCD();
        GridView1.DataBind();
    }
}
